<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 15-4-13
 * Time: 下午2:05
 * @author 郑钟良<zzl@ourstu.com>
 */

namespace Admin\Controller;

use Admin\Builder\AdminConfigBuilder;
use Admin\Builder\AdminListBuilder;
use Admin\Builder\AdminTreeListBuilder;

class LeavetypeController extends AdminController
{
    protected $userTagModel;
    public function index()
    {
        $ddd=M('core_leave_type');
        $list = $ddd->order('status desc,id desc')->select();
        $this->assign('ddd',$list);
        $this->display();
    }
    public function add()
    {
       
    if(IS_POST){
        $df['title']=I('title');
        $df['status']=I('status');
        $df['sort']="1";
        $df['create_time']=time();
        $data = M('core_leave_type')->add($df);
        $this->success('添加成功',U('index'));
        
    }else{
        $this->display();
    }
    }
      public function del(){
        $id = array_unique((array)I('id',0));

        if ( empty($id) ) {
            $this->error(L('_ERROR_DATA_SELECT_').L('_EXCLAMATION_'));
        }

        $map = array('id' => array('in', $id) );
        if(M('core_leave_type')->where($map)->delete()){
            // S('DB_CONFIG_DATA',null);
            //记录行为
            $this->success(L('_SUCCESS_DELETE_'));
        } else {
            $this->error(L('_FAIL_DELETE_'));
        }
    }
    public function jihuo(){
        $id = array_unique((array)I('id',0));

        if ( empty($id) ) {
            $this->error(L('_ERROR_DATA_SELECT_').L('_EXCLAMATION_'));
        }

        $map = array('id' => array('in', $id) );
          $model_object->status = 1;
                $result = $model_object->where($map)->save();
                if($result){
                    $this->success('激活成功!');
                }else{
                    $this->error('激活失败!');
                }
    }
    public function shachu()
    {
       $d=M('core_leave_type')->where('id='.I('tid'))->delete();
       if($d){

           $this->success('删除成功',U('index'));
       }else{
           $this->error('删除失败');
       }
    }
    public function bianji()
    {
       if(IS_POST){
        $f['title']=I('title');
        $f['update_time']=time();
        $s=M('core_leave_type')->where('id='.I('tid'))->save($f);
        $this->success('修改成功',U('index'));
       }else{
        $gg=M('core_leave_type')->where('id='.I('tid'))->find();
        $this->assign('gg',$gg);
        $this->display();
       }
    }
    public function xianshi()
    {
        $d=M('core_leave_type')->where('id='.I('tid'))->getField("sort");
        if($d==1){
            $this->error('已经显示',U('index'));
        }else{
            $s['sort']='1';
            $f=M('core_leave_type')->where('id='.I('tid'))->save($s);
            $this->success('取消显示',U('index'));
        }
    }
    public function xianshi1()
    {
        $d=M('core_leave_type')->where('id='.I('tid'))->getField("sort");
        if($d==0){
            $this->display();
        }else{
           $s['sort']='0';
           $f=M('core_leave_type')->where('id='.I('tid'))->save($s);
           $this->success('显示成功',U('index'));
        }
    }
   
} 